from django.shortcuts import render
from django.http import HttpResponse

from Area.models import AreaInfo

import pypinyin


# Create your views here.

def test(req):
    """test-connect"""
    return HttpResponse(render(req,'BookAppTemplates/test.html'))


def country(req):
    """国"""
    countyr = AreaInfo.objects.filter(type='0')
    return HttpResponse(render(req, 'AreaTemplates/country.html', {"country": countyr}))
    pass


def province(req):
    """省"""
    country = AreaInfo.objects.filter(type="0")
    countryName = country[0]
    province = AreaInfo.objects.filter(type="1")
    return HttpResponse(render(req, 'AreaTemplates/province.html', {"province": province, "countryName": countryName}))
    pass


def city(req, pid):
    """城市"""
    city = AreaInfo.objects.filter(type="2", pid=pid)
    return HttpResponse(render(req, 'AreaTemplates/city.html', {"city": city}))
    pass


def town(req, pid):
    """县城"""
    print(pid)
    town = AreaInfo.objects.filter(type='3', pid=pid)

    return HttpResponse(render(req, "AreaTemplates/town.html", {"town": town}))
